﻿(function () {
    var api = {};
    function MapPoint(lng, lat) {
        this.lng = lng;
        this.lat = lat;
    }
    api.MapPoint = MapPoint;
    (function () {
        function max(a, b) {
            return Math.max(a, b);
        }

        function min(a, c) {
            return Math.min(a, c);
        }

        function lw(a, b, c) {
            a = max(a, b);
            a = min(a, c);
            return a;
        }

        function ew(a, b, c) {
            while (a > c)
                a -= c - b;
            while (a < b)
                a += c - b;
            return a;
        }

        function oi(a) {
            return Math.PI * a / 180;
        }

        function Td(a, b, c, d) {
            return 6370996.81 * Math.acos(Math.sin(c) * Math.sin(d) + Math.cos(c) * Math.cos(d) * Math.cos(b - a));
        }
        function Wv(a, b) {
            if (!a || !b)
                return 0;
            a.lng = ew(a.lng, -180, 180);
            a.lat = lw(a.lat, -74, 74);
            b.lng = ew(b.lng, -180, 180);
            b.lat = lw(b.lat, -74, 74);
            return Td(oi(a.lng), oi(b.lng), oi(a.lat), oi(b.lat));
        }
        function getDistance(a, b) {
            return Wv(a, b);
        }
        api.getDistance = getDistance;
    })();
    window.mapLibs = api;
})();